/**
 * @Astruts2NoConfig.as
 * 
 * @author sodaChen mail:asframe@163.com
 * @version 1.0
 * <br>Copyright (C), 2012 ASFrame.com
 * <br>This program is protected by copyright laws.
 * <br>Program Name:ASFrame AStruts2
 * <br>Date:2012-6-18
 */
package
{
	import com.asframe.astruts2.AStrutst2Init;
	import com.asframe.astruts2.context.IAStrutsContext;
	import com.asframe.astruts2.example.LoginMediator;
	import com.asframe.astruts2.example.LoginView;
	import com.asframe.astruts2.interfaces.impl.SpriteRootContainer;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.utils.getTimer;
	
	/**
	 * Astruts2没有配置文件的测试例子
	 * @author sodaChen
	 * @Date:2012-6-18
	 */
	public class Astruts2NoConfig extends SpriteRootContainer
	{
		private var context:IAStrutsContext;
		public function Astruts2NoConfig()
		{
			super();
			addEventListener(Event.ADDED_TO_STAGE,onStage);
		}
		private function onStage(event:Event):void
		{
			context = new AStrutst2Init(this).initContext();
			//注册相关的View
			context.registerView("loginView",LoginView,LoginMediator);
			context.registerBean("this is AStruts2","astruts");
			//测试一下性能
			var t:int = getTimer();
			for (var i:int = 0; i < 10000; i++) 
			{
				context.sendNotice(LoginMediator.OPEN_LOGIN,"soda");
				context.sendNotice(LoginMediator.CLOSE_LOGIN,"suving");
				context.sendNotice(LoginMediator.UPDATA,"asframe");
			}
			trace("astrus2花费:" + (getTimer() - t));
			//直接调用
			t = getTimer();
			var mediator:LoginMediator = new LoginMediator();
			for (var j:int = 0; j < 10000; j++) 
			{
//				mediator.openLogin("soda");
//				mediator.closeLogin("suving");
//				mediator.replyNotice(LoginMediator.UPDATA,"asframe");
				mediator.openLogin.apply(mediator,["soda"]);
				mediator.closeLogin.apply(mediator,["suving"]);
				mediator.replyNotice.apply(mediator,["asframe"]);
			}
			trace("apply调用花费:" + (getTimer() - t));
			//结论，性能相差10倍。有优化的空间，开来框架始终是有一部分开销的。方便的同时，表示性能也在下降
			
			t = getTimer();
			for (var k:int = 0; k < 10000; k++) 
			{
				mediator.openLogin("soda");
				mediator.closeLogin("suving");
				mediator.replyNotice(LoginMediator.UPDATA,"asframe");
			}
			trace("直接调用花费:" + (getTimer() - t));
		}
	}
}
